package com.sskj.mine.invite;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.InvireTeamRecord;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

/**
 * @author Hey
 * Create at  2019/05/03
 */
public class TeamActivity extends BaseActivity<TeamPresenter> {

    @BindView(R2.id.reward_tv)
    TextView rewardTv;
    @BindView(R2.id.reward_total_tv)
    TextView rewardTotalTv;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;
    private MVCCoolHelper<List<InvireTeamRecord.InviteList>> mvcHelper;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_team;
    }

    @Override
    public TeamPresenter getPresenter() {
        return new TeamPresenter();
    }

    @Override
    public void initView() {
        setTitle(getString(R.string.mine_teamActivity1));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setDividerColor(color(R.color.mine_divider)));
        slimAdapter = SlimAdapter.create().register(R.layout.mine_team_layout, new SlimInjector<InvireTeamRecord.InviteList>() {
            @Override
            public void onInject(InvireTeamRecord.InviteList data, IViewInjector injector, List<Object> list) {
                injector.text(R.id.id, data.getAccount())
                        .text(R.id.center, data.getGrade())
                        .text(R.id.right, data.getReg_time());
            }
        }).attachTo(recyclerView).updateData(new ArrayList());

        ModelRx2DataSource<InvireTeamRecord.InviteList> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<InvireTeamRecord.InviteList>)
                page -> mPresenter.getRecordList(page+"","20"), 20);
        mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    public void initData() {
        mPresenter.getRecord();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, TeamActivity.class);
        context.startActivity(intent);
    }

    public void updateUi(InvireTeamRecord record) {
        rewardTv.setText(record.getZt_count());
        rewardTotalTv.setText(record.getTeam_count());
    }

}
